package com.hzj.service;

import com.hzj.pojo.OrderInfo;
import com.hzj.pojo.UserInfo;
import com.hzj.utils.IPUtils;
import com.hzj.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class MailSend {

    @Autowired
    JavaMailSenderImpl mailSender;
    @Autowired
    RedisUtil redisUtil;

    @Async
    public void mail(OrderInfo orderInfo, HttpServletRequest request) {
        //更新成功发送短信提醒
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("预约成功提醒");//标题
        message.setText("你好，您预约的" + orderInfo.getHosname() + "|" + orderInfo.getDepname() + "|" + orderInfo.getTitle() + "  预约成功，请到" + orderInfo.getFetchAddress() + "取号");// 内容
        message.setFrom("1733013921@qq.com");//从哪个邮箱mail
//        System.out.println("发送邮箱ip"+IPUtils.getIpAddr(request));
        UserInfo userInfo= (UserInfo) redisUtil.get("userInfo"+ redisUtil.get("ip"));
        System.out.println("发送邮箱号"+userInfo.getPhone());
        message.setTo(userInfo.getPhone());//发送到哪个邮箱
        mailSender.send(message);
    }
}
